package com.hardroid.workload.ui.widget;

import android.content.Context;
import android.view.LayoutInflater;
import android.widget.Checkable;
import android.widget.TableLayout;
import android.widget.TextView;

import com.hardroid.workload.R;
import com.hardroid.workload.workcalc.Employer;
import com.hardroid.workload.workcalc.WorkUnit;

public class UnitItemView extends TableLayout implements Checkable{

	public WorkUnit unit;
	public int id;
	
	public TextView idView;
	public TextView nameView;	
	public TextView unitView;
	public TextView jobView;	
	
	public boolean checked =false;
	
	public UnitItemView(Context context,  WorkUnit unit, int id) {
		// TODO Auto-generated constructor stub
		super(context);
		this.unit = unit;
		this.id = id;
		LayoutInflater inflater = (LayoutInflater)context.getSystemService(
				  Context.LAYOUT_INFLATER_SERVICE);

		inflater.inflate(R.layout.list_item_unit, this, true);
		
		idView = (TextView) findViewById(R.id.list_item_unit_id);
		nameView = (TextView) findViewById(R.id.list_item_unit_name);		
		unitView = (TextView) findViewById(R.id.list_item_unit_unit);
		jobView = (TextView) findViewById(R.id.list_item_unit_job);
				
		setUnit(unit, id);
	}
	
	public UnitItemView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}
	
	public void setUnit ( WorkUnit unit, int id){
		this.unit = unit;
		this.id = id;
		idView.setText((id+1)+"");
		nameView.setText(unit.getNamaResponden());		
		unitView.setText(unit.getUnitKerja());
		jobView.setText(unit.getJabatanResponden());
			
	}
	

	@Override
	public boolean isChecked() {
		// TODO Auto-generated method stub
		return checked;
	}

	@Override
	public void setChecked(boolean checked) {
		// TODO Auto-generated method stub
		this.checked = checked;
	}

	@Override
	public void toggle() {
		// TODO Auto-generated method stub
		setChecked(!checked);
	}

}
